#!/bin/bash

#  NOTE: run as root
#  prints a list of files of ALL file under the
#  directory - passed as the first argument

#  e.g. >>sudo ./filelister /home/zeke/docs

d=$1
if [ -d "$d" ]   #argument is given but invalid
   then
      echo ""
      echo "All files under directory: \"$d\""
      echo ""
   else
      echo "error: must pass a valid directory"
      exit 1
fi
output=file.autogenerate
`rm $output`

count=0
files=$(find $d/*)
for X in $files
do
   if [ -f $X ]
   then        

      count=$((count+1))        
      echo "$X"
      echo "$count,\"$X\","\"""\"","\"""\""|" >> "$output"
      
   fi
done

echo ""
echo "see $output for output..."
echo ""

